import { _decorator, Component, Node, sys, tween, Tween, Vec3 } from 'cc';
import { StaminaSystem } from './StaminaSystem';
import { losChannel } from '../SDK/losChannel';
import loskc from '../SDK/loskc';
const { ccclass, property } = _decorator;

@ccclass('LoginUI')
export class LoginUI extends Component {
    @property(Node)
    private videoSp: Node = null!;
    @property(Node)
    private videoLb: Node = null!;

    @property(Node)
    btnGet: Node = null;

    private _tw: Tween<Node> = null;

    start() {
        this._tw = tween(this.btnGet).sequence
            (
                tween(this.btnGet).to(0.4, { scale: new Vec3(1.12, 1.12, 1.12) }),
                tween(this.btnGet).to(0.4, { scale: new Vec3(1, 1, 1) })
            )
            .repeatForever()
            .start()
    }


    /**
     * OnGetClick
     */
    public onGetClick() {
        losChannel.instance().showVideo({
            sucCall: () => {
                StaminaSystem.instance.addStamina(10)
                if (this._tw)
                    this._tw.stop()
                this.node.removeFromParent()
                sys.localStorage.setItem('loginGetRewardTime', Date.now().toString())
            },
            failCall: () => {
            },
            endCall: () => {
            }
        })
    }
    /**
     * onClose
     */
    public onClose() {
        this.node.removeFromParent()
    }
    protected onEnable(): void {
        losChannel.instance().doAction(2, ['ks', 'ks2', 'ks3']);
        losChannel.instance().doAction(2, ['hw', 'honor'], (enabled, val) => {
            if (enabled && loskc.chance(val / 100)) {
                losChannel.instance().showCustomAd();
            }
        })
        losChannel.instance().doAction(22, ['hw'], (enabled, val) => {
            this.videoLb.active = enabled;
            this.videoSp.active = !enabled;
        });
    }
}